package com.snake.springboot.custom.service.impl.base;

import com.github.pagehelper.Page;
import com.snake.springboot.custom.api.model.base.CustRoleModel;
import com.snake.springboot.custom.api.request.base.CustRoleQuery;
import com.snake.springboot.custom.api.request.page.PageQuery;
import com.snake.springboot.custom.api.service.base.CustRoleService;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustRoleDO;
import com.snake.springboot.custom.dao.mybatis.mappers.base.CustRoleMapper;
import com.snake.springboot.custom.service.assemble.base.CustRoleAssemble;
import com.snake.springboot.custom.service.utils.PageUtils;
import org.snake.common.result.ReturnList;
import org.snake.common.utils.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 商户角色实现类Service
 * 类{@code CustRoleServiceImpl} </br>
 * 创建时间 2025/02/08 09:36
 * @author yangxt
 * @see
 */
@Service
public class CustRoleServiceImpl implements CustRoleService{

    @Autowired
    private CustRoleMapper custRoleMapper;

    @Override
    public CustRoleModel addCustRole(CustRoleModel model) {
        CustRoleDO roleDO = CustRoleAssemble.roleDOAss(model,true);
        custRoleMapper.insert(roleDO);
        return model;
    }

    @Override
    public void modifyCustRole(CustRoleModel model) {
        CustRoleDO roleDO = CustRoleAssemble.roleDOAss(model,false);
        custRoleMapper.update(roleDO);
    }

    @Override
    public void removeCustRole(String id) {
        custRoleMapper.delete(id);
    }

    @Override
    public ReturnList<CustRoleModel> queryCustRoleList(PageQuery<CustRoleQuery> params) {
        Page<Object> objects = PageUtils.forcePage(params.getPage());
        CustRoleDO queryDO=CustRoleAssemble.roleDOAss(params.getParams());
        List<CustRoleDO> roleDOList = custRoleMapper.queryCustRoleList(queryDO);
        List<CustRoleModel> roleModels = ListUtils.copy(roleDOList, CustRoleModel.class);
        return new ReturnList<>(roleModels,objects.getTotal());
    }
}
